package com.lsh.oms.core.records.core;

import com.lsh.oms.core.service.tool.Criteria;
import com.lsh.oms.core.service.tool.Pageable;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Optional;

public interface Return {

    Long id();

    String number();

    Status status();

    Occasion occasion();

    void start();

    void run(Map<String, Object> request);

    void check(Map<String, Object> request);

    void confirm(Map<String, Object> request);

    void fillDetails(List<ReturnDetail> details);

    void preDeliver(Map<String, Object> request);

    void deliver(Map<String, Object> request);

    void returned(Map<String, Object> request);

    void terminate(Map<String, Object> request);

    void cancel(Map<String, Object> request);

    void refund(Map<String, Object> request);

    void refundNotify(Map<String, Object> request);

    Pageable<ReturnResult> returnResults(Criteria criteria, long page, long pageLimit);

    Optional<ReturnResult> returnResult(Long id);

    Optional<ReturnDetail> returnDetail(Long id);

    Map<String, List<Map<String, Object>>> relations();

    enum Occasion {
        // 现场
        BEFORE_SIGN,
        // 售后
        AFTER_SIGN
    }

    enum Status {
        // 待审核
        PENDING,
        // 待取货
        PRE_DELIVER,
        // 已取货
        DELIVERED,
        // 已返仓
        RETURNED,
        // 已定损
        CHECKED,
        // 已完成
        TERMINATED,
        // 已取消
        CANCELED;
    }

    interface ReturnDetail {

        Long id();

        Long returnId();

        boolean isWeighingGoods();

        BigDecimal quantity();

        BigDecimal actualQuantity();

        BigDecimal returnedQuantity();

        BigDecimal amount();

        BigDecimal actualAmount();

        BigDecimal returnedAmount();

        void updateActualQuantity(BigDecimal quantity);

        void update(Map<String, Object> request);
    }
}
